package cn.jt_808.jt808.vo.req;

import cn.jt_808.jt808.vo.PackageData;

/**
 * 终端位置信息汇报
 * @author limeng
 */
public class TerminalLocationMsgReport extends PackageData {

    public TerminalLocationMsgReport() {
    }

    public TerminalLocationMsgReport(PackageData packageData) {
        this();
        this.channel = packageData.getChannel();
        this.checkSum = packageData.getCheckSum();
        this.msgBodyBytes = packageData.getMsgBodyBytes();
        this.msgHeader = packageData.getMsgHeader();
        byte[] bytes = packageData.getMsgBodyBytes();
        String hex = bytesToHexString(bytes);
        String photoNum = msgHeader.getTerminalPhone();
        String  lat = hex.substring(16,24);//纬度
        int iLat = HexStringToInt(lat);
        double dLat = iLat/1000000d;
        String  lng = hex.substring(24,32);//经度
        int iLng = HexStringToInt(lng);
        double dlng = iLng/1000000d;
        String height = hex.substring(32,36);//海拔
        int iHeight = HexStringToInt(height);
        String speed = hex.substring(36,40);//速度
        int iSpeed = HexStringToInt(speed);
        double dSpeed = iSpeed/10d;
        String direction = hex.substring(40,44);//方向
        int iDirection = HexStringToInt(direction);
        String date = hex.substring(44,56);//时间
    }

    /**
     * byte[]转十六进制String
     */
    public String bytesToHexString(byte[] bArr) {
        StringBuffer sb = new StringBuffer(bArr.length);
        String sTmp;

        for (int i = 0; i < bArr.length; i++) {
            sTmp = Integer.toHexString(0xFF & bArr[i]);
            if (sTmp.length() < 2)
                sb.append(0);
            sb.append(sTmp.toUpperCase());
        }
        return sb.toString();
    }

    /**
     * 16进制字符串转十进制int
     */
    public static int HexStringToInt(String HexString) {
        int inJTFingerLockAddress = Integer.valueOf(HexString, 16);
        return inJTFingerLockAddress;
    }

}
